package com.zyd.config;

import com.google.common.collect.Lists;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;

import java.util.List;

/**
 * Created by Jason on 5/11/16.
 */
@Configuration
public class HttpMessageConverterConfig {

    @Bean
    public HttpMessageConverters messageConverters() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
                new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
                new AllEncompassingFormHttpMessageConverter(), converter);
        return new HttpMessageConverters() {
            @Override
            public List<HttpMessageConverter<?>> getConverters() {
                return converters;
            }
        };
    }
}
